<?php
/**
 * FastApp.
 * 8/20/24
 * @Author 深色的海 (wx:deepsea_0024)
 * @Contact telegram:deepsea159 
 */

/**
 * 开盲盒
 * @param $prizes
 * @return int|string|null
 */
function openBlindBox($prizes): int|string|null
{
    $totalProbability = array_sum($prizes);
    $random = mt_rand(1, $totalProbability);
    foreach ($prizes as $prize => $probability) {
        if ($random <= $probability) {
            return $prize;
        }
        $random -= $probability;
    }
    return null;
}

/**
 * 双色球
 * @param int $groups 球组数
 * @return string
 */
function drawDoubleColorBall(int $groups = 7): string
{
    $redBalls = range(1, 33);
    shuffle($redBalls);
    $selectedRedBalls = array_slice($redBalls, 0, $groups - 1);
    sort($selectedRedBalls);
    $selectedRedBalls[] = mt_rand(1, 16);
    return implode(' ', $selectedRedBalls);
}

/**
 * 数组相同位置比较
 * @param array $arr1
 * @param array $arr2
 * @param $indexes
 * @return bool
 */
function compareArraysAtIndexes(array $arr1, array $arr2, $indexes): bool
{
    foreach ($indexes as $index) {
        if (!isset($arr1[$index]) || !isset($arr2[$index]) || $arr1[$index] !== $arr2[$index]) {
            return false;
        }
    }
    return true;
}